package cn.oscar.controller;

import cn.oscar.service.BlogService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import commonUtils.dto.BlogDTO;
import commonUtils.entities.Blog;
import commonUtils.entities.Restful;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/blogs")
public class BlogConrtoller {

    @Autowired
    private BlogService blogService;

    /**
     * 博客分页查询
     * @param page 当前页码
     * @param pageSize 一页的大小
     * @param name 条件查询
     * @return 返回分页查询结果
     */
    @GetMapping("/page")
    public Restful<Page<BlogDTO>> selectByPage(int page,int pageSize,String name){
        return blogService.selectByPage(page,pageSize,name);
    }

    /**
     * 删除博客内容
     * @param ids 博客的ids
     * @return 返回是否删除成功信息
     */
    @DeleteMapping
    public Restful<String> deleteByIds(@RequestParam Long[] ids){
        return blogService.deleteByIds(ids);
    }

    /**
     * 锁定或解锁博客
     * @param blog 博客内容
     * @return 返回是否锁定成功信息
     */
    @PutMapping
    public Restful<String> updateLockBlog(@RequestBody Blog blog){
        return blogService.lockBlog(blog);
    }

    /**
     * 发布博客
     * @param blog 博客内容
     * @return 返回是否发布成功信息
     */
    @PostMapping
    public Restful<String> addBlog(@RequestBody Blog blog){
        return blogService.addBlog(blog);
    }

    /**
     * 根据博客id查看博客
     * @param id 传入的博客id
     * @return 返回博客，评论相关的详细内容
     */
    @GetMapping("/{id}")
    public Restful<BlogDTO> selectBlogById(@PathVariable Long id){
        return blogService.getBlogById(id);
    }

}
